<?php
/**
 * Created by jinqiang on 2025/5/15 10:06.
 * Copyright (c) 2025, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Produce;


use App\Http\Controllers\Controller;
use App\Http\Services\Produce\ProcessingManageService;
use Illuminate\Http\Request;

class ProcessingManageController extends Controller
{
    public function list(Request $request, ProcessingManageService $processingManageService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $processingManageService->search($param);
        return result($res);
    }

    public function detail(Request $request, ProcessingManageService $processingManageService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $processingManageService->detail((Int)$param['id']);
        return result($res);
    }

    public function del(Request $request, ProcessingManageService $processingManageService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $processingManageService->del((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    public function check(Request $request, ProcessingManageService $processingManageService)
    {
        $this->validate($request, [
            'id' => 'required',
            'action' => 'required|in:CHECK,UNCHECK'
        ]);
        $param = $request->all();
        $res = $processingManageService->check((Int)$param['id'], $param['action']);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }

    //保存
    public function save(Request $request, ProcessingManageService $processingManageService)
    {
        $this->validate($request, [
            'edit_form' => 'required',
            'edit_count' => 'required',
            'edit_detail_count' => 'required',
            'edit_item' => 'required',
            'edit_item_colour' => 'required',
            'edit_item_detail' => 'required',
            'edit_item_detail_batch' => 'required',
            'size_list' => 'required'
        ]);
        $param = $request->all();
        $res = $processingManageService->save($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }
}
